package com.s3u4.concurrence.pool;

import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by Captain on 28/03/2018.
 */
public class Client {

    public static Set<String> ids = new CopyOnWriteArraySet<String>();

    public static class TestThread implements Runnable {
        public void run() {
            String id = String.valueOf(Thread.currentThread().getId());
            if ( !ids.contains(id) ){
                System.out.println(id);
            }
            ids.add(id);
        }
    }


    public static void main(String[] args) throws InterruptedException {
        ExecutorService executorService = Executors.newSingleThreadExecutor();

        for ( int i = 0 ; i <= 100 ; i++){
            executorService.execute(new TestThread());
        }

        Thread.sleep(4000);

        executorService.shutdown();
    }


}
